package cn.shop.dys.util;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import cn.shop.dys.bean.UserInfo;

/**
 * 用户处理工具
 * Created by sunjian on 2016/4/19.
 */
public class MyUserInfoUtil {
    private static MyUserInfoUtil mMyUserInfoUtil;
    private static List<UserInfo> mUserInfos ;
    private MyUserInfoUtil(){
        mUserInfos=new ArrayList<>();
    }
    public static MyUserInfoUtil createInstance(){
        if(mMyUserInfoUtil==null){
            return new MyUserInfoUtil();
        }else {
            return mMyUserInfoUtil;
        }
    }
    public void addUserInfo(UserInfo userInfo){
        Log.d("test1",userInfo.toString());
        if(mUserInfos.size()==0){
            Log.d("test3", userInfo.toString());
            UserInfo myUserInfo=new UserInfo();
            myUserInfo.setUserid(userInfo.getUserid());
            mUserInfos.add(userInfo);
        }else {
            if(!mUserInfos.contains(userInfo)){
                mUserInfos.remove(0);
                mUserInfos.add(userInfo);
            }
        }
    }
    public UserInfo getUserInfo(){
        Log.d("test2",mUserInfos.get(0).toString());
        return mUserInfos.size()==0?null:mUserInfos.get(0);
    }
}
